<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('预定列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
		<div class="row">
		
			<div class="col-sm-12 search-collapse">
				<form id="config-form">
					<div class="select-list">
						<ul>
							<li class="select-time">
								<input class="time-input" name="date" placeholder="请输入日期" />
							</li>
							<li>
								电话：<input type="text" name="phone"  />
							</li>
							<li>
								姓名：<input type="text" name="name"/>
							</li>
							
							<li >
								状态：<select name="status" >
								      <option value="">所有</option>
								      <option value="0">预定中</option>
								      <option value="1">已消费</option>
								      <option value="2">取消</option>
							      </select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
		        <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="rest:reserve:add">
		            <i class="fa fa-plus"></i> 新增
		        </a>
		        <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="rest:reserve:remove">
		            <i class="fa fa-remove"></i> 删除
		        </a>
	        </div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
	    </div>
	</div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('rest:reserve:edit')}]];
        var removeFlag = [[${@permission.hasPermi('rest:reserve:remove')}]];
        var prefix = ctx + "/restaurant/reserve";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "预定",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键'
                },
                {
                    field: 'date',
                    title: '日期'
                },
                {
                    field: 'name',
                    title: '姓名'
                },
                {
                    field: 'phone',
                    title: '电话'
                },
                {
                    field: 'num',
                    title: '人数'
                },
				{
					field: 'remark',
					title: '备注'
				},
				{
					field: 'total',
					title: '价格'
				},
                {
					title: '状态',
					field: 'status',
					align: 'center',
					formatter: function (value, row, index) {
						if(value == 0) {
							return '预定中'
						} else if (value == 1){
							return '已消费'
						} else {
							return '取消'
						}
					}
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="openBind(\'' + row.id + '\')">查看菜品</a>');
	                    
	                    if(row.status == 0){
	                    	actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>修改</a> ');
	                    	actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="xiaofei(\'' + row.id + '\')">去消费</a>');
		                    actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="quxiao(\'' + row.id + '\')">取消</a>');
	                    }
	                    actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
	                    
	                    
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        function openBind(id){
        	var url = ctx + "/restaurant/reserve/bind/" + id
        	$.modal.open('菜品详情', url)
        }
        
        function quxiao(id){
        	$.modal.confirm("确认要取消该预定吗？", function() {
				$.operate.post(prefix + "/updateStatus", { "id": id, "status": 2 });
			})
        }

		function xiaofei(id){
			var url = ctx + "/restaurant/reserve/bindFreeTable/" + id
        	$.modal.open('安排桌子', url,600,400)
		}

    </script>
</body>
</html>